package strcy.cn.market.service.Impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import strcy.cn.market.mapper.ShoppingCartsMapper;
import strcy.cn.market.pojo.ShoppingCarts;
import strcy.cn.market.pojo.VO.ShoppingCartsVO;
import strcy.cn.market.service.ShoppingCartsService;
import strcy.cn.market.utils.ThreadLocalUtil;

import java.util.List;
import java.util.Map;

@Service
public class ShoppingCartsServiceImpl implements ShoppingCartsService {
    @Autowired
    private ShoppingCartsMapper shoppingCartsMapper;

    @Override
    public void add(ShoppingCarts shoppingCarts) {
        Map<String,Object> map = ThreadLocalUtil.get();
        Integer userId = (Integer) map.get("id");
        shoppingCarts.setUserId(userId);
        shoppingCartsMapper.add(shoppingCarts);
    }

    @Override
    public void update(Integer quantity, Integer cartId) {
        shoppingCartsMapper.update(quantity,cartId);
    }

    @Override
    public List<ShoppingCartsVO> list() {
        Map<String,Object> map = ThreadLocalUtil.get();
        Integer userId = (Integer) map.get("id");
        List<ShoppingCartsVO> list = shoppingCartsMapper.list(userId);
        return list;
    }
    @Override
    public void deleteById(Integer cartId) {
        shoppingCartsMapper.deleteById(cartId);
    }

    @Override
    public void deleteByIds(List<Integer> cartIds) {
        shoppingCartsMapper.deleteByIds(cartIds);
    }
}
